package com.sample.kokou;

import java.sql.SQLException;

import android.content.Intent;
import android.view.View;
import android.os.Bundle;

import com.j256.ormlite.android.apptools.OrmLiteBaseListActivity;
import com.j256.ormlite.dao.Dao;

public class SqliteSampleActivity extends OrmLiteBaseListActivity<SampleDBHelper> {
    Dao<Person, Integer> dao = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        getListView().setOnItemClickListener(new EditPerson(this));
        getListView().setOnItemLongClickListener(new DeletePerson(this));

        try {
            dao = getHelper().getDao(Person.class);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        try {
            setListAdapter(new PersonListAdapter(this , dao.queryForAll()));
        } catch(SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public void newPerson(View v) {
        Intent i = new Intent(this, PersonActivity.class);
        i.putExtra("action", "new");
        startActivity(i);
    }
}